import http from "@/api";
import { Device, GatewayType } from "@/api/interface/iot";
import { ResPage } from "../../interface";

/**
 * @name 硬网关管理模块
 */

// * 获取硬列表
export const getGatewayList = (params: Device.ReqGateway, type: GatewayType) => {
	return http.get<ResPage<Device.ResGateway[]>>(`/${changeType(type)}/find`, params, { headers: { noLoading: true } });
};
// * 新增硬列表
export const addGateway = (params: Device.ReqGateway, type: GatewayType) => {
	return http.post<Device.ResGateway>(`/${changeType(type)}/add`, params);
};
// * 删除硬列表
export const removeGateway = (params: Device.ReqGateway, type: GatewayType) => {
	return http.post(`/${changeType(type)}/remove`, params);
};
// * 获取硬列表详情
export const getGateway = (params: Device.ReqGateway, type: GatewayType) => {
	return http.get<Device.ResGateway>(`/${changeType(type)}/get`, params);
};
// * 编辑硬列表
export const modifyGateway = (params: Device.ReqGateway, type: GatewayType) => {
	return http.post(`/${changeType(type)}/modify`, params);
};
// 另存为产品
export const saveToProduct = (params: any, type: GatewayType) => {
	return http.post(`/${changeType(type)}/save/product`, params);
};
// 同步配置
export const syncGateway = (params: any, type: GatewayType) => {
	return http.post(`/${changeType(type)}/config/set`, params);
};
const changeType = (type: string) => {
	return type.replaceAll("_", "-");
};
// 查询参数
export const syncGetGateway = (params?: any) => {
	return http.post(`/gateway/config/get`, params);
};
// 网关批量分组
export const changeGroup = (params: any, type: GatewayType) => {
	return http.post(`/${changeType(type)}/changeGroup`, params);
};
